
library(ggplot2)
library(zoo)
library(dplyr)
library(haven)
library(cowplot)

figdata<-read_dta("figdata.dta")
figdata2<-read_dta("figdata2.dta")


#relative freq of protest per year, globally, all + viol + nonviol

p<- ggplot(figdata, aes(x=year, y=proportion)) + 
  geom_line(aes(y = propnon, colour = "propnon", linetype = "propnon")) +
  geom_line(aes(y = propviol, colour = "propviol", linetype = "propviol")) + 
  geom_line(aes(y = proportion, colour = "proportion", linetype = "proportion")) 
q<- p + labs(x="Year", y="Frequency of campaigns (sample relative)") +
  scale_linetype_discrete(name = " ", labels = c("Nonviolent","All campaigns","Violent")) + 
  scale_color_discrete(name = " ", labels = c("Nonviolent","All campaigns","Violent")) + theme_classic() +theme(axis.title = element_text(size = 8), panel.grid.major.y = element_line())

q
save_plot("campaigns.png",q,dpi=500, base_asp=2)


#summary of different transitions

p<- ggplot(figdata2, aes(x=year, y=proportion)) + 
  geom_smooth(method="loess",
              aes(y = proportion, colour = "proportion", 
                  linetype = "proportion"), span =0.075, se=FALSE, size=0.5) + 
  geom_smooth(method="loess",
              aes(y = propdem, colour = "propdem", 
                  linetype = "propdem"), span =0.075, se=FALSE, size=0.5) + 
  geom_smooth(method="loess",
              aes(y = propdirc, colour = "propdirc", 
                  linetype = "propdirc"), span =0.075, se=FALSE, size=0.5)

q<- p+scale_color_brewer(palette="Paired") + labs(x="Year", y="Frequency of transitions (sample relative)") +
  scale_linetype_discrete(name = " ", labels = c("Democratizing","Non-democratizing","All transitions")) + 
  scale_color_discrete(name = " ", labels = c("Democratizing","Non-democratizing","All transitions")) + theme_classic() + theme(axis.title = element_text(size = 8), panel.grid.major.y = element_line()) 

save_plot("transitions.png",q,dpi=500, base_asp=2)

